﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Data;
using Atom.Entity;

namespace Atom.Utility
{
    public class ReadXml
    {

        public static string GetFenMianType(string name)
        {
            //if (list == null)
            //{
            //List<SqlEntity> t = new List<SqlEntity>();
            string path = System.Windows.Forms.Application.StartupPath + "\\sql.xml";
            if (File.Exists(path))
            {
                try
                {
                    DataSet ds = new DataSet();
                    ds.ReadXml(path);
                    foreach (DataRow row in ds.Tables["SQLXML"].Rows)
                    {
                        if (row["Name"].ToString().Equals(name))
                        {
                            //SqlEntity type = new SqlEntity();
                            //type.Name = row["Name"].ToString();
                            //type.SQL = row["SQL"].ToString();
                            //t.Add(type);
                            return row["SQL"].ToString();
                        }
                    }
                }
                catch (Exception e)
                {
                    throw new Exception("获取配置文件失败！详细信息:" + e.Message);
                }
            }

            return string.Empty;
            // list = t;
            //}

            //return list;
        }

        /// <summary>
        /// 得到病种集合
        /// </summary>
        /// <returns></returns>
        public static List<BZEntity> GetBZEntity()
        {
            List<BZEntity> bzentitys = new List<BZEntity>();
            string path = System.Windows.Forms.Application.StartupPath + "\\ConfigExcel.xml";
            if (File.Exists(path))
            {
                try
                {
                    DataSet ds = new DataSet();
                    ds.ReadXml(path);
                    foreach (DataRow row in ds.Tables["BZXML"].Rows)
                    {

                        BZEntity entity = new BZEntity();
                        entity.BZName = row["NAME"].ToString();
                        entity.BZCode = row["CODE"].ToString();
                        entity.Index = Convert.ToInt32(row["INDEX"].ToString());
                        bzentitys.Add(entity);
                    }
                }
                catch (Exception e)
                {
                    throw new Exception("获取配置文件失败！详细信息:" + e.Message);
                }
            }

            return bzentitys;

        }

        /// <summary>
        /// 得到药品监测项目集合
        /// </summary>
        /// <returns></returns>
        public static List<CodeDetailEntity> GetCodeDetailEntity()
        {
            List<CodeDetailEntity> bzentitys = new List<CodeDetailEntity>();
            string path = System.Windows.Forms.Application.StartupPath + "\\ConfigExcel.xml";
            if (File.Exists(path))
            {
                try
                {
                    DataSet ds = new DataSet();
                    ds.ReadXml(path);
                    foreach (DataRow row in ds.Tables["CODEXML"].Rows)
                    {

                        CodeDetailEntity entity = new CodeDetailEntity();
                        entity.Name = row["NAME"].ToString();
                        entity.Code = row["CODE"].ToString();
                        entity.Index = Convert.ToInt32(row["INDEX"].ToString());
                        bzentitys.Add(entity);
                    }
                }
                catch (Exception e)
                {
                    throw new Exception("获取配置文件药品检查项目失败！详细信息:" + e.Message);
                }
            }

            return bzentitys;

        }

        /// <summary>
        /// 得到检查监测项目集合
        /// </summary>
        /// <returns></returns>
        public static List<ItemDetailEntity> GetItemDetailEntity()
        {
            List<ItemDetailEntity> bzentitys = new List<ItemDetailEntity>();
            string path = System.Windows.Forms.Application.StartupPath + "\\ConfigExcel.xml";
            if (File.Exists(path))
            {
                try
                {
                    DataSet ds = new DataSet();
                    ds.ReadXml(path);
                    foreach (DataRow row in ds.Tables["ITEMXML"].Rows)
                    {

                        ItemDetailEntity entity = new ItemDetailEntity();
                        entity.Name = row["NAME"].ToString();
                        entity.Code = row["CODE"].ToString();
                        entity.Index = Convert.ToInt32(row["INDEX"].ToString());
                        bzentitys.Add(entity);
                    }
                }
                catch (Exception e)
                {
                    throw new Exception("获取配置文件药品检查项目失败！详细信息:" + e.Message);
                }
            }

            return bzentitys;

        }
    }
}
